﻿using System.Data;
using System.Linq;
using WebUI.DAL;

namespace WebUI.BL.PostCode
{
    public class PostCodes
    {
        AdlerContextDataContext adlerContextDb = new AdlerContextDataContext();

        // Show City.
        public DataTable Get_City()
        {
            DataTable dt = new DataTable();
            var query = adlerContextDb.SP_FONT_POSTCODE_CITY();
            dt = query.ConvertToDataTable(record => new object[] { query });
            return dt;
        }

        // Show District.
        public DataTable Get_District(string cityname)
        {
            DataTable dt = new DataTable();
            var query = adlerContextDb.SP_FONT_POSTCODE_DISTRICT(cityname);
            dt = query.ConvertToDataTable(record => new object[] { query });
            return dt;
        }

        // Show Ward.
        public DataTable Get_Ward(string district)
        {
            DataTable dt = new DataTable();
            var query = adlerContextDb.SP_FONT_POSTCODE_WARD(district);
            dt = query.ConvertToDataTable(record => new object[] { query });
            return dt;
        }

        public int getpostcodeid(string city, string district, string ward)
        {
            var query = from n in adlerContextDb.tbl_PostCodes
                        where n.City.Contains(city) && n.District.Contains(district) && n.Ward.Contains(ward) && n.Status == 1
                        select n.PostCode;
            return query.FirstOrDefault();
        }
    }
}
